﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using Irrlicht.Net;
using Irrlicht.Net.IO;

namespace Irrlicht.Net.Scene
{
    public class SceneNodeAnimator : AttributeExchangingObject
    {
        #region PInvoke
        [DllImport(@"IrrlichtW.dll", CallingConvention = CallingConvention.Cdecl)]
        internal static extern void SceneAnimator_AnimateNode(IntPtr scnAnim, IntPtr node, uint timeMs);

        [DllImport(@"IrrlichtW.dll", CallingConvention = CallingConvention.Cdecl)]
        internal static extern IntPtr SceneAnimator_CreateClone(IntPtr scnAnim, IntPtr node, IntPtr newManager);

        [DllImport(@"IrrlichtW.dll", CallingConvention = CallingConvention.Cdecl)]
        internal static extern NodeAnimatorTypes SceneAnimator_GetType(IntPtr scnAnim);

        [DllImport(@"IrrlichtW.dll", CallingConvention = CallingConvention.Cdecl)]
        internal static extern bool SceneAnimator_HasFinished(IntPtr scnAnim);

        [DllImport(@"IrrlichtW.dll", CallingConvention = CallingConvention.Cdecl)]
        internal static extern bool SceneAnimator_IsEventReceiverEnabled(IntPtr scnAnim);
        #endregion

        public SceneNodeAnimator(IntPtr pointer)
        {
            this.pointer = pointer;
        }

        /// <summary>
        /// Animates a scene node. 
        /// </summary>
        /// <param name="node"></param>
        /// <param name="timeMs"></param>
        public virtual void AnimateNode(SceneNode node, uint timeMs)
        {
            SceneAnimator_AnimateNode(this.pointer, node.pointer, timeMs);
        }

        /// <summary>
        /// Creates a clone of this animator.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="newManager"></param>
        /// <returns></returns>
        public virtual SceneNodeAnimator CreateClone(SceneNode node, SceneManager newManager)
        {
            return new SceneNodeAnimator(SceneAnimator_CreateClone(this.pointer, node.pointer, newManager.pointer));
        }
 
        /// <summary>
        /// Gets the type of the scene node animator. 
        /// </summary>
        public NodeAnimatorTypes Type
        {
            get
            {
                return SceneAnimator_GetType(this.pointer);
            }
        }
 
        /// <summary>
        /// Returns if the animator has finished.
        /// </summary>
        /// <returns></returns>
        public virtual bool HasFinished()
        {
            return SceneAnimator_HasFinished(this.pointer);
        }
 
        /// <summary>
        /// Returns true if this animator receives events. 
        /// </summary>
        /// <returns></returns>
        public virtual bool IsEventReceiverEnabled()
        {
            return SceneAnimator_IsEventReceiverEnabled(this.pointer);
        }
    }
}
